import layoutHeaderAside from '@/layout/header-aside'

// 由于懒加载页面太多的话会造成webpack热更新太慢，所以开发环境不使用懒加载，只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)

/**
 * 在主框架内显示
 */
let frameIn = [
  {
    path: '/',
    redirect: { name: 'index' },
    component: layoutHeaderAside,
    children: [
      // 首页
      {
        path: 'index',
        name: 'index',
        meta: { auth: true },
        component: _import("system/index/index-optimized"),
        componentUrl: "system/index/index-optimized"
      },
      // 租户管理
      {
        path: 'tenant/account-management',
        name: 'tenant-account-management',
        meta: { title: '开户管理', auth: true },
        component: _import('tenant/account-management')
      },
      {
        path: 'tenant/tenant-monitor',
        name: 'tenant-tenant-monitor',
        meta: { title: '租户监控', auth: true },
        component: _import('tenant/tenant-monitor')
      },
      // 财务管理
      {
        path: 'finance/charge-billing',
        name: 'finance-charge-billing',
        meta: { title: '充值缴费', auth: true },
        component: _import('finance/charge-billing')
      },
      {
        path: 'finance/financial-reconciliation',
        name: 'finance-financial-reconciliation',
        meta: { title: '财务对账', auth: true },
        component: _import('finance/financial-reconciliation')
      },
      {
        path: 'finance/charge-record',
        name: 'finance-charge-record',
        meta: { title: '充值记录', auth: true },
        component: _import('finance/charge-record')
      },
      {
        path: 'finance/account-settlement',
        name: 'finance-account-settlement',
        meta: { title: '销户结算', auth: true },
        component: _import('finance/account-settlement')
      },
      // 设备管理
      {
        path: 'device/electric-meter',
        name: 'device-electric-meter',
        meta: { title: '电表管理', auth: true },
        component: _import('device/electric-meter')
      },
      {
        path: 'device/water-meter',
        name: 'device-water-meter',
        meta: { title: '水表管理', auth: true },
        component: _import('device/water-meter')
      },
      // 系统管理
      {
        path: 'system/operation-record',
        name: 'system-operation-record',
        meta: { title: '操作记录', auth: true },
        component: _import('system/operation-record')
      },
      {
        path: 'system/charging-scheme',
        name: 'system-charging-scheme',
        meta: { title: '收费方案', auth: true },
        component: _import('system/charging-scheme')
      },
      {
        path: 'system/timing-scheme',
        name: 'system-timing-scheme',
        meta: { title: '定时方案', auth: true },
        component: _import('system/timing-scheme')
      },
      // 报表管理
      {
        path: 'report/device-report',
        name: 'report-device-report',
        meta: { title: '设备报表', auth: true },
        component: _import('report/device-report')
      },
      // 保留原有权限管理和基础配置
      {
        path: 'sys/user',
        name: 'sys-user',
        meta: { title: '权限管理', auth: true },
        component: _import('sys/user')
      },
      {
        path: 'sys/config',
        name: 'sys-config',
        meta: { title: '基础配置', auth: true },
        component: _import('sys/config')
      },
      // 报表管理
      {
        path: 'report/device',
        name: 'report-device',
        meta: { title: '设备报表', auth: true },
        component: _import('report/device')
      },
      // 系统 前端日志
      {
        path: 'log',
        name: 'log',
        meta: { title: '前端日志', auth: true },
        component: _import('system/log'),
        componentUrl: 'system/log'
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: _import('system/function/refresh'),
        componentUrl: 'system/function/refresh'
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: _import('system/function/redirect'),
        componentUrl: 'system/function/redirect'
      }
    ]
  }
]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: _import('system/login')
  },
  // 设备信息
  {
    path: '/meterinfo',
    name: 'meterinfo',
    component: _import('operationManagement/meter')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  {
    path: '*',
    name: '404',
    component: _import('system/error/404')
  }
]

/**
 * 大屏
 */
const screenPage = [
  {
    path: '/screen',
    name: 'screen',
    meta: {
      auth: true
    },
    component: _import('screen/index')
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    meta: {
      auth: true
    },
    component: _import('screen/dashboard')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

let frameInRoutesNew = sessionStorage.getItem('frameInRoutesNew')
if (frameInRoutesNew) {
  frameInRoutesNew = JSON.parse(frameInRoutesNew)
  console.log(frameInRoutesNew)
  frameIn[0].children = frameInRoutesNew[0].children.map(item => {
    return {
      ...item,
      component: _import(item.componentUrl)
    }
  })
}

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage,
  ...screenPage,
  
  // debug
  {
    path: '/reportPrint',
    name: 'reportPrint',
    component: _import('components/reportPrint')
  },
  {
    path: '/screenV2',
    name: 'screenV2',
    component: _import('system/index/page-component')
  }
]

